package com.wxjfkg.workflow.impl;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fivestar.customer.service.UserSelectService;
import com.fivestar.workflow.CmsUser;
import com.wxjfkg.workflow.dao.CmsUserDao;

@Service("userSelectService")
public class UserSelectServiceImpl implements UserSelectService {

	@Autowired
	private CmsUserDao cmsUserDao;
	
	/**
	 * 工单大区经理
	 */
	public List<String> selectAreaManager(String createPerson) {
		CmsUser user = new CmsUser();
		user.setUserName(createPerson);
		//判断创建人是否是大区经理,如果是创建人是大区经理,直接返回大区经理
		boolean dqjl = cmsUserDao.isDqjlRole(user) >= 1;
		if(dqjl){
			return Arrays.asList(createPerson);
		}
		//创建人不是大区经理,则返回该客户经理所在机构的大区经理
		return cmsUserDao.selectAreaManager(user);
	}

	/**
	 * 工单复审
	 */
	public List<String> selectRepeatAudit(String createPerson) {
		return cmsUserDao.queryUserByRole("orderReAudit");
	}

	/**
	 * 电核
	 */
	public List<String> selectCallCredit() {
		return cmsUserDao.queryUserByRole("callCredit");
	}

	/**
	 * 风控初审
	 */
	public List<String> selectRiskApproval() {
		return cmsUserDao.queryUserByRole("riskApproval");
	}

	/**
	 * 风控复审
	 */
	public List<String> selectReRiskApproval() {
		return cmsUserDao.queryUserByRole("reRiskApprova");
	}

	/**
	 * 城市经理尽调
	 */
	public List<String> selectCityManagerSurvey() {
		return cmsUserDao.queryUserByRole("cityManagerSurvey");
	}
	
	/**
	 * 风控经理尽调
	 */
	public List<String> selectRiskManagerSurvey() {
		return cmsUserDao.queryUserByRole("riskManagerSurvey");
	}
	
	/**
	 * 风控经理初审
	 */
	public List<String> selectRiskManagerApprove(){
		return cmsUserDao.queryUserByRole("riskManagerApprove");
	}
	
	/**
	 * 用信风控复审
	 */
	public List<String> selectReRiskManagerApprove(){
		return cmsUserDao.queryUserByRole("reRiskManagerApprove");
	}

	/**
	 * 资金专员审核
	 */
	public List<String> selectCapitalApprove(){
		return cmsUserDao.queryUserByRole("capitalApprove");
	}
	
	/**
	 * 内控专员审核
	 */
	public List<String> selectInterControlApprove(){
		return cmsUserDao.queryUserByRole("interControlApprove");
	}
	
	/**
	 * 财务放款
	 */
	public List<String> selectFinanceLoan(){
		return cmsUserDao.queryUserByRole("financeLoan");
	}

	/**
	 * 授信任务分配
	 */
	@Override
	public List<String> selectCreditDistribution() {
		return  cmsUserDao.queryUserByRole("creditDistribution");
	}

	/**
	 * 通过角色名称查询账户信息
	 */
	public List<String> selectCmsUsersByRole(String roleName) {
		return cmsUserDao.queryUserByRole(roleName);
	}

	/**
	 * 风险委员会复审
	 */
	@Override
	public List<String> selectReRiskApproval20() {
		return  cmsUserDao.queryUserByRole("reRiskApprova20");
	}

	/**
	 * 公司风险委员会审核
	 */
	@Override
	public List<String> selectReRiskApproval200() {
		return  cmsUserDao.queryUserByRole("reRiskApprova200");
	}
	
	/**
	 * 贷后外审调查
	 */
	@Override
	public List<String> selectCreditChangeOutAuditor() {
		return  cmsUserDao.queryUserByRole("outauditor");
	}
	
	/**
	 * 贷后外审调查
	 */
	@Override
	public List<String> selectCreditChangeFinalApprove() {
		return  cmsUserDao.queryUserByRole("finalApprove");
	}

	@Override
	public List<CmsUser> selectUserByRole(String roleName) {
		return cmsUserDao.queryCmsUserByRole(roleName);
	}

}
